﻿using System;
using Autodesk.Revit.DB;

namespace YJKRevitDimensionText.VerticalAutoDim.OutWallSearch
{
	public class OutWallData
	{
		public XYZ Orientation { get; set; }

		public Element Element { get; set; }

		public Curve Curve { get; set; }

		public bool TryMergeCommonOutWall(OutWallData outWallData)
		{
			try
			{
				if (this.Element == null || outWallData == null || outWallData.Element == null)
				{
					return false;
				}
				if (this.Element.Id.IntegerValue != outWallData.Element.Id.IntegerValue || this.Element.Id == ElementId.InvalidElementId)
				{
					return false;
				}
				XYZ endPoint = this.Curve.GetEndPoint(0);
				XYZ endPoint2 = this.Curve.GetEndPoint(1);
				XYZ endPoint3 = this.Curve.GetEndPoint(1);
				bool flag = false;
				if (this.Curve.GetEndPoint(0).IsAlmostEqualTo(outWallData.Curve.GetEndPoint(0)))
				{
					endPoint = this.Curve.GetEndPoint(1);
					endPoint2 = outWallData.Curve.GetEndPoint(1);
					endPoint3 = this.Curve.GetEndPoint(0);
					flag = true;
				}
				else if (this.Curve.GetEndPoint(0).IsAlmostEqualTo(outWallData.Curve.GetEndPoint(1)))
				{
					endPoint = this.Curve.GetEndPoint(1);
					endPoint2 = outWallData.Curve.GetEndPoint(0);
					endPoint3 = this.Curve.GetEndPoint(0);
					flag = true;
				}
				else if (this.Curve.GetEndPoint(1).IsAlmostEqualTo(outWallData.Curve.GetEndPoint(0)))
				{
					endPoint = this.Curve.GetEndPoint(0);
					endPoint2 = outWallData.Curve.GetEndPoint(1);
					endPoint3 = this.Curve.GetEndPoint(1);
					flag = true;
				}
				else if (this.Curve.GetEndPoint(1).IsAlmostEqualTo(outWallData.Curve.GetEndPoint(1)))
				{
					endPoint = this.Curve.GetEndPoint(0);
					endPoint2 = outWallData.Curve.GetEndPoint(0);
					endPoint3 = this.Curve.GetEndPoint(1);
					flag = true;
				}
				if (flag)
				{
					if (this.Curve is Line)
					{
						this.Curve = Line.CreateBound(endPoint, endPoint2);
						return true;
					}
					if (this.Curve is Arc)
					{
						this.Curve = Arc.Create(endPoint, endPoint2, endPoint3);
						return true;
					}
				}
			}
			catch
			{
				return false;
			}
			return false;
		}
	}
}
